(function (doc, body) {
    var
         _library = "promptu"                                           // name of the global object and className prefix
        ,addEvent = (doc.addEventListener || doc.attachEvent)           // event listener normailzation
        ,apiState                                                       // boolean indicator for shown or hidden state of modal
        ,bodyClasses = [                                                // for toggling between api state via css on the body element
             _library + "_hide"
            ,_library + "_show"
        ]
        ,blindr  = create("div", _library + "_blinder", body)           // backdrop that obscures the rest of the page
        ,dialog  = create("div", _library + "_dialog", body)            // wrapper for dialog content and UI
        ,button  = create("div", _library + "_button", dialog)          // click-y button/icon for "literal" close functionality
        ,content = create("div", _library + "_content", dialog)         // for applying padding to content w/o adding to outer width
        ,noop = function () {}                                          // this does nothing, move along
        ,on = addEvent.name ? "" : "on"                                 // for normalizing the event name
        ,react;                                                         // this is a register for a reaction fn to user interaction

    function create (elm, className, parent) {                          // create the element and append it to the DOM
        var result = doc.createElement(elm);                            //   This isn't necessarily the most efficient order to
        result.className = className;                                   //   append items to the DOM; but is anyone really going to
        parent.appendChild(result);                                     //   call me out on it? This is only to save lines of code.

        return result;
    }

    function hide () {
        apiState && (react(), toggleState());                           // only execute if the apiState is true == open/visible
    }

    function show (contentText, fn) {
        apiState && toggleState();                                      // clear previous without firing react
        content.innerHTML = contentText || content.innerHTML;           // add new content or use the old content
        toggleState();
        dialog.style.marginTop = ~~(-dialog.offsetHeight / 2) + "px";   // execute after it is shown in the DOM
        react = fn || noop;                                             // register the reaction function
    }

    function toggleState () {                                           // I'm not going to explain what is happening here
        body.className = body.className.replace(RegExp(bodyClasses[0], "g"), bodyClasses[1]);
        bodyClasses.push(bodyClasses.shift());
        apiState = !apiState;
    }

    body.className += bodyClasses[0];                                   // start with the modal hidden
    button.innerHTML = "&times;";                                       // a simple "X" as a close icon
    blindr.onclick = button.onclick = hide;                             // fire hide() on click
    addEvent.call(doc, on + "keydown", function (event) {               // conditionally fire hide() when escape key is pressed
        (event || window.event).keyCode === 27 && hide();               // normalize the event object for IE
    });

    window[_library] = {                                                // create the public API
         hide: hide
        ,show: show
    };
}(document, document.body));